function showDiv(str, btn) {

	let divs = document.getElementsByClassName('ToggleForm');
	for (let div of divs) {
		div.style.display = "none";
	}
	document.getElementById(str)
		.style.display = "block";

	let MDListItem = document.getElementsByClassName('mdui-list-item');
	for (let md of MDListItem) {
		md.style.color = '';
		md.style.background = '';
		md.getElementsByTagName('i')[0].style.color = '';
	}
	document.getElementById(btn)
		.style.color = '#1a73e8';
	document.getElementById(btn)
		.style.background = '#e8f0fe';
	var tempBtn = document.getElementById(btn);
	tempBtn.getElementsByTagName('i')[0].style.color = '#1a73e8';
}

function Select_the_file() {
	document.getElementById("excel")
		.click();
}

function UploadYes() {

	var file = document.querySelector('#excel')
		.files[0];
	if (file == undefined) {
		mdui.snackbar({
			message: '你还未选择文件',
			position: 'top'
		});
	} else {
		mdui.snackbar({
			message: '解析文件中',
			position: 'right-bottom'
		});
		readWorkbookFromLocalFile(file, function (workbook) {
			readWorkbook(workbook);
		});
		
	}
}

function delTable() {
	document.getElementById("errortable")
		.innerHTML = "";
	document.getElementById("table0")
		.innerHTML = "";
	document.getElementById("table1")
		.innerHTML = "";
	document.getElementById("table2")
		.innerHTML = "";
	document.getElementById("table3")
		.innerHTML = "";
	mdui.snackbar({
		message: '执行清理当前所有表格',
		position: 'top'
	});
}

function dowload(table) {
	mdui.snackbar({
		message: '执行下载文件中',
		position: 'top'
	});
	
	var blob = sheet2blob(XLSX.utils.table_to_sheet(document.getElementById(table)));
	//设置链接
	var link = window.URL.createObjectURL(blob);
	var a = document.createElement("a"); //创建a标签
	a.download = dowloadifname(table); //设置被下载的超链接目标（文件名）
	a.href = link; //设置a标签的链接
	document.body.appendChild(a); //a标签添加到页面
	a.click(); //设置a标签触发单击事件
	document.body.removeChild(a); //移除a标签
}

function dowloadifname(str) {
	var date = new Date();
	var time = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + "_" + date.getHours() + "-" + date.getMinutes() + "-";
	if (str == "tableAll3") {
		return time + "三星级.xlsx"
	} else if (str == "tableAll2") {
		return time + "二星级.xlsx"
	} else if (str == "tableAll1") {
		return time + "一星级.xlsx"
	} else if (str == "tableAll0") {
		return time + "未通过星级.xlsx"
	}
}

function sheet2blob(sheet, sheetName) {
	sheetName = sheetName || 'sheet1';
	var workbook = {
		SheetNames: [sheetName],
		Sheets: {}
	};
	workbook.Sheets[sheetName] = sheet;
	// 生成excel的配置项
	var wopts = {
		bookType: 'xlsx', // 要生成的文件类型
		bookSST: false, // 是否生成Shared String Table，官方解释是，如果开启生成速度会下降，但在低版本IOS设备上有更好的兼容性
		type: 'binary'
	};
	var wbout = XLSX.write(workbook, wopts);
	var blob = new Blob([s2ab(wbout)], {
		type: "application/octet-stream"
	});
	// 字符串转ArrayBuffer
	function s2ab(s) {
		var buf = new ArrayBuffer(s.length);
		var view = new Uint8Array(buf);
		for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
		return buf;
	}
	return blob;
}